package com.biyao.service.model.base;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;

import com.biyao.schedulingdao.base.TGrindWheelBasicMapper;
import com.biyao.schedulingentity.base.TBearingBoxEntity;
import com.biyao.schedulingentity.base.TGrindWheelBasicEntity;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:19
 */
@Service
public class TGrindWheelBasicService extends ServiceImpl<TGrindWheelBasicMapper, TGrindWheelBasicEntity>{

    public Page list(int pageNum, int pageSize){

        EntityWrapper<TGrindWheelBasicEntity> tGrindWheelBasicentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tGrindWheelBasicentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }

    List formatRecords(List<TGrindWheelBasicEntity> list){
        List resList=new ArrayList();
        for(TGrindWheelBasicEntity tGrindWheelBasicEntity:list){
            Map map=formatEntity(tGrindWheelBasicEntity);
            resList.add(map);
        }
        return resList;
    }

    Map formatEntity(TGrindWheelBasicEntity tGrindWheelBasicEntity){
        Map map=new HashMap(16);
        //砂轮
        if(tGrindWheelBasicEntity.getId()!=null){
           map.put("id",tGrindWheelBasicEntity.getId());
        }
        //砂轮编号
        if(tGrindWheelBasicEntity.getCode()!=null){
           map.put("code",tGrindWheelBasicEntity.getCode());
        }
        //生产厂家
        if(tGrindWheelBasicEntity.getManufacturer()!=null){
           map.put("manufacturer",tGrindWheelBasicEntity.getManufacturer());
        }
        //生产日期
        if(tGrindWheelBasicEntity.getManufactureDate()!=null){
           map.put("manufactureDate",tGrindWheelBasicEntity.getManufactureDate());
        }
        //砂轮类型
        if(tGrindWheelBasicEntity.getType()!=null){
           map.put("type",tGrindWheelBasicEntity.getType());
        }
        //当前状态
        if(tGrindWheelBasicEntity.getState()!=null){
           map.put("state",tGrindWheelBasicEntity.getState());
        }
        //备注
        if(tGrindWheelBasicEntity.getRemark()!=null){
           map.put("remark",tGrindWheelBasicEntity.getRemark());
        }
        //
        if(tGrindWheelBasicEntity.getCreateTime()!=null){
           map.put("createTime",tGrindWheelBasicEntity.getCreateTime());
        }
        //
        if(tGrindWheelBasicEntity.getUpdateTime()!=null){
           map.put("updateTime",tGrindWheelBasicEntity.getUpdateTime());
        }
        //
        if(tGrindWheelBasicEntity.getCreateBy()!=null){
           map.put("createBy",tGrindWheelBasicEntity.getCreateBy());
        }
        //
        if(tGrindWheelBasicEntity.getUpdateBy()!=null){
           map.put("updateBy",tGrindWheelBasicEntity.getUpdateBy());
        }
        return map;
    }

    public Boolean selectCodeIsRepeat(String code) {
        EntityWrapper<TGrindWheelBasicEntity> grindWheelBasicEntityEntityWrapper=new EntityWrapper<>();
        grindWheelBasicEntityEntityWrapper.eq("code",code);
        List<TGrindWheelBasicEntity> list=selectList(grindWheelBasicEntityEntityWrapper);
        if(list.size()>0){
            return true;
        }
        return false;
    }

    public Boolean selectUpdateCodeIsRepeat(String code,Integer id) {
        EntityWrapper<TGrindWheelBasicEntity> grindWheelBasicEntityEntityWrapper=new EntityWrapper<>();
        grindWheelBasicEntityEntityWrapper.eq("code",code);
        List<TGrindWheelBasicEntity> list=selectList(grindWheelBasicEntityEntityWrapper);
        if(list.size()>0){
            if(list.get(0).getId().intValue()!=id.intValue()){
                return true;
            }
            return false;
        }
        return false;
    }

}

